home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fixfat.zip / FAT.FIX next >
Text File  |  1987-10-26  |  17KB  |  356 lines

  1. October 20, 1987
  2.  
  3. It doesn't take a trojan to wipe out your hard disk!  My FATs 
  4. (File Allocation Table) were wiped out when I had several TSRs
  5. loaded, a DOS shell on top of those and I loaded another
  6. COMMAND.COM on top of that.  When my word processor ran out of
  7. memory the whole stack of programs crashed and wrote garbage
  8. over my FAT.  When I rebooted the computer it wouldn't boot
  9. off the hard disk.  I hadn't backed up my drives for four months
  10. and I was facing the loss of close to 40MB of memory off two 20MB
  11. drives.
  12.  
  13. When I ran CHKDSK it came up with the cyptic message "Probable 
  14. non-DOS disk.  Continue (Y/N)?"  Of course it was a DOS disk.  
  15. What was going on?  
  16.  
  17. Well I finally figured out I had access to a couple of 
  18. subdirectories but my disk was obviously wasted.  I was 
  19. desperate.  What do I do now?  Norton Utilities wouldn't read the 
  20. disk saying I was running out of memory.  I didn't have MACE so I 
  21. don't know how that program would have worked.  
  22.  
  23. Then I remembered -- there are two copies of the FAT on a disk.  
  24. It seems DOS writes two copies of the FAT every time a change is 
  25. made but it only reads the first when reading the disk.  The 
  26. second FAT isn't even used for CHKDSK.  Was that FAT still in one 
  27. piece?  Fortunately it was.  Now all I had to do was get the 
  28. second copy of the FAT copied over to where the first one was.  
  29. How do you do this?  If you're like me you take a stab at it 
  30. using DEBUG.  It actually took me three days to figure out how 
  31. the process worked but once I knew all the steps it only took 
  32. about 15 minutes for the entire operation.  
  33.  
  34. I'm writing this file in the hope that I can help someone else in 
  35. similar circumstances to bypass the three day portion.  I have 
  36. two Seagate ST-225's formatted under 3.10 and I'm not sure that 
  37. everything will work the same for other versions of DOS or if you 
  38. have a RLL controller.  But what are your alternatives?
  39.  
  40. First let me explain how a hard drive is set up at the byte 
  41. level.  Your disk is set up with sectors labeled in ascending 
  42. sequence starting at zero.  Depending under what DOS you are 
  43. formatted with, the Boot sector occupies the first sector, the FAT 
  44. is in sectors 1-82, the root directory is sector 83 and all the 
  45. rest of your subdirectories and files occupy the remainder of the 
  46. disk.  So right now we have:
  47.             Sector 0  Boot record
  48.             Sector 1-82 FATs
  49.             Sector 83 Root directory
  50.             Sector 84-? Subdirectories and files
  51.             
  52. Using DEBUG the BOOT sector should look like this under 3.10 
  53. (similar under other versions).  Notice the identifying IBM 3.1 
  54. on the first line.  This is the version the disk was formatted 
  55. under.
  56.  
  57. xxxx:0100  EB 29 90 49 42 4D 20 20-33 2E 31 00 02 04 01 00   .).IBM  3.1.....   
  58. xxxx:0110  02 00 02 3B A2 F8 29 00-11 00 04 00 11 00 80 00   ...;..).........   
  59. xxxx:0120  00 00 00 00 0F 00 00 00-00 01 00 FA 33 C0 8E D0   ............3...   
  60. xxxx:0130  BC 00 7C 16 07 BB 78 00-36 C5 37 1E 56 16 53 BF   ..|...x.6.7.V.S.   
  61. xxxx:0140  20 7C B9 0B 00 FC AC 26-80 3D 00 74 03 26 8A 05    |.....&.=.t.&..   
  62. xxxx:0150  AA 8A C4 E2 F1 06 1F 89-47 02 C7 07 20 7C FB CD   ........G... |..   
  63. xxxx:0160  13 72 67 A0 10 7C 98 F7-26 16 7C 03 06 1C 7C 03   .rg..|..&.|...|.   
  64. xxxx:0170  06 0E 7C A3 34 7C A3 2C-7C B8 20 00 F7 26 11 7C   ..|.4|.,|. ..&.|   
  65. xxxx:0180  8B 1E 0B 7C 03 C3 48 F7-F3 01 06 2C 7C BB 00 05   ...|..H....,|...   
  66. xxxx:0190  A1 34 7C E8 96 00 B8 01-02 E8 AA 00 72 19 8B FB   .4|.........r...   
  67. xxxx:01A0  B9 0B 00 BE BE 7D F3 A6-75 0D 8D 7F 20 BE C9 7D   .....}..u... ..}   
  68. xxxx:01B0  B9 0B 00 F3 A6 74 18 BE-5F 7D E8 61 00 32 E4 CD   .....t.._}.a.2..   
  69. xxxx:01C0  16 5E 1F 8F 04 8F 44 02-CD 19 BE A8 7D EB EB A1   .^....D.....}...   
  70. xxxx:01D0  1C 05 33 D2 F7 36 0B 7C-FE C0 A2 31 7C A1 2C 7C   ..3..6.|...1|.,|   
  71. xxxx:01E0  A3 32 7C BB 00 07 A1 2C-7C E8 40 00 A1 18 7C 2A   .2|....,|.@...|*   
  72. xxxx:01F0  06 30 7C 40 50 E8 4E 00-58 72 CF 28 06 31 7C 76   .0|@P.N.Xr.(.1|v   
  73. xxxx:0200  0C 01 06 2C 7C F7 26 0B-7C 03 D8 EB D9 8A 2E 15   ...,|.&.|.......   
  74. xxxx:0210  7C 8A 16 1E 7C 8B 1E 32-7C EA 00 00 70 00 AC 0A   |...|..2|...p...   
  75. xxxx:0220  C0 74 22 B4 0E BB 07 00-CD 10 EB F2 33 D2 F7 36   .t".........3..6   
  76. xxxx:0230  18 7C FE C2 88 16 30 7C-33 D2 F7 36 1A 7C 88 16   .|....0|3..6.|..   
  77. xxxx:0240  1F 7C A3 2E 7C C3 B4 02-8B 16 2E 7C B1 06 D2 E6   .|..|......|....   
  78. xxxx:0250  0A 36 30 7C 8B CA 86 E9-8B 16 1E 7C CD 13 C3 0D   .60|.......|....   
  79. xxxx:0260  0A 4E 6F 6E 2D 53 79 73-74 65 6D 20 64 69 73 6B   .Non-System disk   
  80. xxxx:0270  20 6F 72 20 64 69 73 6B-20 65 72 72 6F 72 0D 0A    or disk error..   
  81. xxxx:0280  52 65 70 6C 61 63 65 20-61 6E 64 20 73 74 72 69   Replace and stri   
  82. xxxx:0290  6B 65 20 61 6E 79 20 6B-65 79 20 77 68 65 6E 20   ke any key when    
  83. xxxx:02A0  72 65 61 64 79 0D 0A 00-0D 0A 44 69 73 6B 20 42   ready.....Disk B   
  84. xxxx:02B0  6F 6F 74 20 66 61 69 6C-75 72 65 0D 0A 00 49 42   oot failure...IB   
  85. xxxx:02C0  4D 42 49 4F 20 20 43 4F-4D 49 42 4D 44 4F 53 20   MBIO  COMIBMDOS    
  86. xxxx:02D0  20 43 4F 4D 00 00 00 00-00 00 00 00 00 00 00 00    COM............   
  87. xxxx:02E0  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................   
  88. xxxx:02F0  00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA   ..............U.   
  89.  
  90. I've listed the boot sector only so that you can compare it to 
  91. your's and see if it's intact.  In my case it wasn't and I had to 
  92. get it from another disk.  Alternatively you could enter it onto 
  93. the disk using debug.
  94.  
  95. The next portion of your disk is the FAT.  Here is what the first 
  96. portion of mine looks like.
  97.  
  98. xxxx:0300  F8 FF FF FF 03 00 04 00-05 00 06 00 FF FF 08 00   ................   
  99. xxxx:0310  09 00 0A 00 0B 00 0C 00-0D 00 0E 00 0F 00 10 00   ................   
  100. xxxx:0320  11 00 12 00 13 00 14 00-FF FF 16 00 17 00 18 00   ................   
  101. xxxx:0330  19 00 1A 00 1B 00 1C 00-1D 00 1E 00 1F 00 20 00   .............. .   
  102. xxxx:0340  FF FF FF FF FF FF FF FF-25 00 26 00 27 00 28 00   ........%.&.'.(.   
  103. xxxx:0350  29 00 2A 00 2B 00 2C 00-FF FF 2E 00 2F 00 30 00   ).*.+.,...../.0.   
  104. xxxx:0360  31 00 32 00 33 00 34 00-35 00 36 00 37 00 38 00   1.2.3.4.5.6.7.8.   
  105. xxxx:0370  39 00 3A 00 3B 00 3C 00-3D 00 3E 00 3F 00 40 00   9.:.;.<.=.>.?.@.   
  106.  
  107. The FAT is the road map which DOS uses to find it's way around 
  108. your disk.  When DOS needs to access a file it finds the first 
  109. sector the file is in by looking it up in the directory listing.
  110. Then it takes a look at the FAT listing for that sector.  If the 
  111. FAT for that sector is a FFFF there are no more sectors for DOS 
  112. to read.  If there is a number there that is the number to the 
  113. next sector which the file is in.  DOS goes to the next sector 
  114. and continues on until it reaches a FFFF.
  115.  
  116. It's fairly easy to read this.  Each word (2 bytes) corresponds
  117. to a disk sector.  Two rules to this table.  All the numbers are 
  118. in hex and the words have the bytes reversed.  So if you were 
  119. looking at a word from the table that read "EF 12" first you 
  120. would invert them "12 EF".  Next convert them to decimal. 
  121. 12EF hex = 4847 decimal.
  122.  
  123. The first file starts in sector 2, goes to 3, 4, 5 and then
  124. 6 where it reads a FFFF and stops.  Since your system files are 
  125. normally the first files on a disk the first couple of files
  126. should be contiguous.  This will help you locate the start of
  127. your FAT.  
  128.  
  129. Hopefully the next figure will make it clearer.
  130.  
  131. Sector -->   0     1     2     3     4     5     6     7
  132.              |     |     |     |     |     |     |     |
  133.             / \   / \   / \   / \   / \   / \   / \   / \
  134. xxxx:0300  F8 FF FF FF 03 00 04 00-05 00 06 00 FF FF 08 00   ................   
  135.  
  136.  
  137. Sector -->   8     9     10    11    12    13    14    15
  138.              |     |     |     |     |     |     |     |
  139.             / \   / \   / \   / \   / \   / \   / \   / \
  140. xxxx:0310  09 00 0A 00 0B 00 0C 00-0D 00 0E 00 0F 00 10 00   ................   
  141.  
  142.  
  143. Sector -->   16    17    18    19    20    21    22    23
  144.              |     |     |     |     |     |     |     |
  145.             / \   / \   / \   / \   / \   / \   / \   / \
  146. xxxx:0320